package com.jiedeng.controller;

import com.jiedeng.dao.ICheckItemRuleRepository;
import com.jiedeng.model.CheckItemRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 覃远龙
 * @ClassName: CheckItemRuleController
 * @Description:
 * @date 2017/8/22 14:24
 */
@RestController
@RequestMapping("/checkitemRule")
public class CheckItemRuleController {

    @Autowired
    ICheckItemRuleRepository checkItemRuleRepository;

    //----------------- checkItemRule table -------------------//
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public List<CheckItemRule> findAll(){
        return checkItemRuleRepository.findAll();
    }


    @RequestMapping(value = "/findCheckItemRuleByCheckItemId", method = RequestMethod.GET)
    public List<CheckItemRule> findCheckItemRuleByCheckItemId(long checkItemId){
        return checkItemRuleRepository.findByCheckItemId(checkItemId);
    }


    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public CheckItemRule findCheckItemRule(long id){
        return checkItemRuleRepository.getOne(id);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CheckItemRule saveCheckItem(@RequestBody CheckItemRule item){
        return checkItemRuleRepository.save(item);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public void deleteCheckItem(long id){
        checkItemRuleRepository.deleteById(id);
    }
}
